# 种仙人掌
# 冒泡排序
import common
def sort_x(x,size):
	for i in range(size):
		for j in range(0,size - i - 1):
			common.move_abs(x,j)
			if measure() > measure(North):
				swap(North)

def sort_y(y,size):
	for i in range(size):
		for j in range(0,size - i - 1):
			common.move_abs(j,y)
			if measure() > measure(East):
				swap(East)
clear()
while True:
	common.move_abs(0,0)
	size = get_world_size()
	for x in range(size):
		for y in range(size):
			if get_ground_type() != Grounds.Soil:
				till()
			plant(Entities.Cactus)
			move(North)
			if num_items(Items.Power) >= 100:
				use_item(Items.Power)
		move(East)
	for x in range(size):
		sort_x(x,size)
	for y in range(size):
		sort_y(y,size)
	harvest()